package com.itheima.springbootwebtlias.mapper;

import com.itheima.springbootwebtlias.pojo.Clazz;
import com.itheima.springbootwebtlias.pojo.ClazzQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ClazzMapper {
    // 根据条件分页查询班级
    List<Clazz> list(ClazzQueryParam clazzQueryParam);

    // 添加班级
    @Insert("insert into clazz(name, room, begin_date, end_date, master_id, subject, create_time, update_time) " +
            "values (#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    void insert(Clazz clazz);

    // 根据id查询班级
    @Select("select * from clazz where id = #{id}")
    Clazz getById(Integer id);

    // 修改班级信息
    @Update("update clazz set name = #{name}, room = #{room}, begin_date = #{beginDate}, end_date = #{endDate}, master_id = #{masterId}, subject = #{subject}, update_time = #{updateTime} where id = #{id}")
    void update(Clazz clazz);

    // 删除班级信息
    @Delete("delete from clazz where id = #{id}")
    void deleteById(Integer id);

    // 基本查询所有班级
    @Select("select * from clazz")
    List<Clazz> selectALL();

    // 查询指定id班级中的学生人数
    @Select("select count(1) from student where clazz_id = #{id}")
    int isHasStudent(Integer id);

}
